package com.hlm.demo.service.adminlogin;

import com.hlm.demo.entity.ModuleInfo;
import com.hlm.demo.entity.ex.AdminWithRole;
import com.hlm.demo.mapper.AdminLoginMapper;
import com.hlm.demo.mapper.ModuleInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author Ric
 * 登录相关 Service 实现类
 */
@Service
public class AdminLoginService implements IAdminLoginService {

    @Autowired
    AdminLoginMapper adminLoginMapper;

    @Autowired
    ModuleInfoMapper moduleInfoMapper;


    /**
     * 此静态方法的功能 - 向全用户(超管, 普管)中插入非(特有)权限即可查看的共通型模块地址
     *
     * @param moduleInfo 从数据库查出的权限集合
     * @return 包装后的权限集合
     */
    private static List<ModuleInfo> addCommonInfo(List<ModuleInfo> moduleInfo) {
        moduleInfo.add(new ModuleInfo(8, "个人信息", "/user/user_info.html", "/images/information_out.png"));
        moduleInfo.add(new ModuleInfo(9, "修改密码", "/user/user_modi_pwd.html", "/images/password_out.png"));
        return moduleInfo;
    }

    // 获取登录的管理员信息
    @Override
    public AdminWithRole adminInfoSearcher(String username) {
        return adminLoginMapper.adminInfoSearch(username);
    }


    // 普管
    @Override
    public List<ModuleInfo> moduleInfoSearcher(String username) {
        List<ModuleInfo> moduleInfo = moduleInfoMapper.moduleInfoSearch(username);

        return AdminLoginService.addCommonInfo(moduleInfo);
    }

    // 超管
    @Override
    public List<ModuleInfo> allModuleInfoSearcher() {
        List<ModuleInfo> moduleInfo = moduleInfoMapper.allModuleInfoSearch();

        return AdminLoginService.addCommonInfo(moduleInfo);
    }


}

